package com.liuweiheng.cloud.timer;

import com.liuweiheng.base.entity.R;
import org.quartz.*;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import java.util.Date;

/**
 * 任务类
 *
 * 抛出异常只会终止当前定时任务，下个定时任务会继续执行
 * JobDataMap中的基础边变量不可再修改，可传递对象，来修改对象中的属性，也可自己另外使用其他存储方式
 *
 * @author lwh
 * @since 2021/2/1
 */

@Component
@PersistJobDataAfterExecution
public class MyJob implements Job {


    private RestTemplate restTemplate = new RestTemplate();



    JobEntity count;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        JobDetail jobDetail = jobExecutionContext.getJobDetail();

        JobDataMap dataMap = jobExecutionContext.getMergedJobDataMap();

//        ArrayList<Integer> count = (ArrayList) dataMap.get("count");
//
//        count.add(count.get(count.size() - 1) + 1);
//
//        System.out.println(count);


        System.out.println(Thread.currentThread().getName() + "_" + new Date() + "：" + count.getCount());

        count.setCount(count.getCount() + 1);


    }

    public void setCount(JobEntity count) {
        this.count = count;
    }
}
